#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2e5 + 5;
const int M = 998244353;

// a^b % M
ll qpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = res * a % M;
        a = a * a % M;
        b >>= 1;
    }
    return res;
}

int t, n;
int a[N];

ll fac[N], inv[N];

void init() {
    fac[0] = 1;
    for (int i = 1; i < N; i++) {
        fac[i] = (fac[i - 1] * i) % M;
        inv[i] = qpow(i, M - 2);
    }
}

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    init();

    cin >> t;
    while(t--) {
        cin >> n;
        int m = -1;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            m = max(m, a[i]);
        }
        int k = 0, cntm = 0;
        for (int i = 1; i <= n; i++) {
            if (a[i] == m) cntm++;
            if (a[i] == m-1) k++;
        }

        if (cntm > 1) cout << fac[n] << endl;
        else if (k == 0) cout << 0 << endl;
        else {
            ll res = (fac[n] * k % M) * inv[k+1] % M;
            cout << res << endl;
        }
    }
    return 0;
}